package reflection;

public class test03 {

    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println(person.getName());
        //方式1：通过类的对象的getClass方法获得
        Class c1 = person.getClass();
        //方式2:通过全类名使用Class.forName获得
        Class c2 = Class.forName("reflection.Student");
        //方式3：通过类名.class获得
        Class c3 = Student.class;
        System.out.println(c1.hashCode()+"--"+c2.hashCode()+"--"+c3.hashCode());
        //方式4：基本类型的包装类都有一个TYPE属性，可以获得该类的Class对象
        Class c4 = Integer.TYPE;
        System.out.println("c4的类型是:"+c4);
        //方式5：通过子类Class类型的getSuperClass获得父类类型
        Class c5 = c1.getSuperclass();
        System.out.println("c5的类型是:"+c5);
    }

}
class Person{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{

    public Student(){
        this.name = "学生";
    }
}

class Teacher extends Person{
    public Teacher(){
        this.name = "老师";
    }
}
